package com.mgq.java8.lambda;

import java.util.ArrayList;
import java.util.List;
import java.util.function.BiPredicate;

/**
 *
 * @author 马广奇
 * @version 2022-03-26 15:48
 */
public class Apple extends Fruit  {
    private String color;
    private long weight;



    public String getColor() {
        return color;
    }

    public void setColor(String color) {
        this.color = color;
    }

    public long getWeight() {
        return weight;
    }

    public void setWeight(long weight) {
        this.weight = weight;
    }

    @Override
    public String toString() {
        return "Apple{" +
                "color='" + color + '\'' +
                ", weight=" + weight +
                '}';
    }
    public Apple() {
    }
    public Apple(String color) {
        this.color = color;
    }

    public Apple(String color, long weight) {
        this.color = color;
        this.weight = weight;
    }

    public static List<Apple> filterGreenAndWeight(List<Apple> list, BiPredicate<String,Long> predicate) {
        List<Apple> result = new ArrayList<>();
        for (Apple apple : list) {
            if (predicate.test(apple.getColor(), apple.getWeight())) {
                result.add(apple);
            }
        }
        return result;
    }
}
